package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem) {
        checkItemService.add(checkItem);
        return new Result(true, "新增检查项成功");
    }

    @GetMapping("/findAll")
    public Result findAll() {
        List<CheckItem> list = checkItemService.findAll();
        return new Result(true, "查询检查项成功", list);
    }

    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkItemService.findPage(queryPageBean);
        return pageResult;
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        checkItemService.delete(id);
        return new Result(true, "删除检查项成功");
    }

    @GetMapping("/findById")
    public Result findById(Integer id) {
        CheckItem checkItem = checkItemService.findById(id);
        return new Result(true, "查询检查项成功", checkItem);
    }

    @PostMapping("/edit")
    public Result edit(@RequestBody CheckItem checkItem) {
        checkItemService.update(checkItem);
        return new Result(true, "编辑检查项成功");
    }

    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdByCheckGroupId(Integer checkgroupId) {
        List<Integer> list = checkItemService.findCheckItemId(checkgroupId);
        return new Result(true, "查询检查项成功", list);
    }
}
